package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.base.image;
import com.hdax.dm.dto.CarouseDto;
import com.hdax.dm.mappers.ImageMapper;
import com.hdax.dm.mapstucts.CarouseDtoMapper;
import com.hdax.dm.service.imageService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class imageServiceImpl extends ServiceImpl<ImageMapper,image> implements imageService {

    @Autowired
    private CarouseDtoMapper carouseDtoMapper;

    @Override
    public image image(Long targetId, Long type, Long category) {
        QueryWrapper<image> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("targetId",targetId);
        queryWrapper.eq("type",type);
        queryWrapper.eq("category",category);
        return getOne(queryWrapper);
    }

    @Override
    public CommonResponse<List<image>> imagelist() {
        QueryWrapper<image> queryWrapper = new QueryWrapper();
        queryWrapper.eq("type",1L);
        queryWrapper.eq("category",1L);
        queryWrapper.isNotNull("imgUrl");

        IPage<image> page = page(Page.of(1,5),queryWrapper);

        return ResponseUtil.returnSuccess(page.getRecords());
    }
}
